﻿using System;
public interface IShape
{
    double CalculateArea();
    bool IsValid();
}

// 长方形类
public class Rectangle : IShape
{
    public double Length { get; set; }
    public double Width { get; set; }

    public Rectangle(double length, double width)
    {
        Length = length;
        Width = width;
    }

    public double CalculateArea()
    {
        return Length * Width;
    }

    public bool IsValid()
    {
        return Length > 0 && Width > 0;
    }
}

public class Square : IShape
{
    public double Side { get; set; }

    public Square(double side)
    {
        Side = side;
    }

    public double CalculateArea()
    {
        return Side * Side;
    }
    public bool IsValid()
    {
        return Side > 0;
    }
}
public class Triangle : IShape
{
    public double SideA { get; set; }
    public double SideB { get; set; }
    public double SideC { get; set; }

    public Triangle(double sideA, double sideB, double sideC)
    {
        SideA = sideA;
        SideB = sideB;
        SideC = sideC;
    }
    public double CalculateArea()
    {
        double s = (SideA + SideB + SideC) / 2; 
        return Math.Sqrt(s * (s - SideA) * (s - SideB) * (s - SideC));
    }
    public bool IsValid()
    {
        return SideA > 0 && SideB > 0 && SideC > 0 &&
               SideA + SideB > SideC &&
               SideA + SideC > SideB &&
               SideB + SideC > SideA;
    }
}

class Program
{
    static void Main(string[] args)
    {
        Rectangle rectangle = new Rectangle(5, 10);
        Console.WriteLine($"长方形面积: {rectangle.CalculateArea()}");
        Console.WriteLine($"长方形是否合法: {rectangle.IsValid()}");

        Square square = new Square(4);
        Console.WriteLine($"正方形面积: {square.CalculateArea()}");
        Console.WriteLine($"正方形是否合法: {square.IsValid()}");

        Triangle triangle = new Triangle(3, 4, 5);
        Console.WriteLine($"三角形面积: {triangle.CalculateArea()}");
        Console.WriteLine($"三角形是否合法: {triangle.IsValid()}");

       
    }
}